<template>
	<view class="customer">
		<u-navbar title="客户管理" bgColor="#fff" :autoBack="true">
		</u-navbar>
		<view class="addCustomer flex_shu" @tap="addCustomer">
			<image :src="imgUrl + 'addCustomer.png'" mode="" class="addImg"></image>
			<text>添加客户</text>
		</view>
		<scroll-view class="shopUl" :class="classifyIndex==-1?'uiheight':'uiheightTwo'" scroll-y="true" lower-threshold="50"
			@scrolltolower="classifyLower">
			<view class="customerBox" v-for="(item,index) in allShopList" :key="index" @click="customerClick(item)">
				<view class="rightTop" :style="{ background: item.status == 1?'#00BF39':item.status == 2?'#FF8F1F':'#3662EC'}">
					{{item.status == 1?'潜在客户':item.status == 2?'意向客户':'正式客户'}}
				</view>
				<view class="deleteBox" @tap.stop="delCustomer(item.id)">
					<u-icon name="trash-fill" color="#666666"></u-icon>
				</view>
				<view class="customerItembox flex_shu">
					<view class="itemName">
						<text class="u-line-1">{{item.customerName}}</text>
					</view>
					<view class="itemCon flex_heng">
						<view class="itemPhone">
							{{item.phone}}
						</view>
						<view class="itemType">
							客户类型:<text>{{item.type == 1?'个人客户':'公司客户'}}</text>
						</view>
					</view>

					<view class="itemBtm">
						创建时间:<text>{{item.createTime}}</text>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		getCustomerList,
		delCustomer
	} from '@/api/api.js'
	export default {
		data() {
			return {
				imgUrl: this.$imgUrl,
				allShopList: [
					// {
					// 	status: 1,
					// 	createTime: '2042/07/01 00:23',
					// 	customerName: '客户姓名',
					// 	phone: '15929238080',
					// 	type: 1,
					// 	id: '1'
					// },
				],
				pageNum: 1,
			};
		},
		onLoad(options) {},
		onShow() {
			this.pageNum = 1;
			this.allShopList = [];
			this.getCustomerList();
		},
		onReachBottom() {
			this.pageNum++;
			this.getCustomerList()
		},
		methods: {
			//客户点击
			customerClick(item) {

				console.log(item);
				uni.navigateTo({
					url: `/pages/package/customerInfo/customerInfo?customerId=` + item.id
				})
			},
			addCustomer() {
				uni.navigateTo({
					url: `/pages/package/customerInfo/customerInfo`
				})
			},
			//分类列表到底
			classifyLower() {
				console.log('分类列表到底')
			},
			getCustomerList() {
				getCustomerList({
					pageNum: this.pageNum,
					pageSize: 20,
					appUserId: uni.getStorageSync('userInfo').id,
					// dadAppUserId
				}).then(res => {
					if (res.rows.length > 0) {
						this.allShopList = [...this.allShopList, ...res.rows]
					}
				})
			},
			delCustomer(id) {
				uni.showModal({
					title: '提示',
					content: '确定删除吗？',
					success: (res) => {
						if (res.confirm) {
							console.log('用户点击确定');
							delCustomer(id).then(res => {
								if (res.code == 200) {
									this.pageNum = 1;
									this.allShopList = [];
									this.getCustomerList();
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
		},
	}
</script>

<style lang="scss">
	.customer {
		min-height: 100vh;
		padding: 200rpx 28rpx 0;
		box-sizing: border-box;
		background-color: #F6F6F6;

		.addCustomer {
			width: 100%;
			height: 136rpx;

			.addImg {
				width: 84rpx;
				height: 84rpx;
			}

			text {
				color: #000000;
				font-size: 28rpx;
				font-weight: 400;
			}
		}

		.shopUl {
			width: 100%;

			.customerBox {
				width: 100%;
				position: relative;

				.rightTop {
					position: absolute;
					right: 0;
					top: 0;
					width: 144rpx;
					height: 64rpx;
					line-height: 64rpx;
					border-radius: 0 36rpx 0 36rpx;
					opacity: 1;
					color: #ffffff;
					text-align: center;
					font-size: 28rpx;
					font-weight: 500;
					background: #00bf39;
				}

				.deleteBox {
					position: absolute;
					right: 20rpx;
					top: 50%;
					transform: translateY(-50%);

				}

				.customerItembox {
					margin-top: 28rpx;
					width: 100%;
					border-radius: 36rpx;
					opacity: 1;
					background: #ffffff;
					padding: 28rpx;
					box-sizing: border-box;
					align-items: flex-start;

					.itemName {
						color: #000000;
						font-size: 28rpx;
						font-weight: 500;
					}

					.itemCon {
						width: 100%;
						align-items: center;
						justify-content: flex-start;
						color: #333333;
						font-size: 24rpx;
						font-weight: 400;
						margin: 18rpx 0;

						.itemPhone {
							width: 40%;
						}

						.itemType {
							text {
								color: #000000;
							}
						}

					}

					.itemBtm {
						width: 100%;
						color: #333333;
						font-size: 24rpx;
						font-weight: 400;

						text {
							color: #000000;
						}
					}

				}

			}
		}
	}
</style>